package ui.activity.profit.presenter;


import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import base.BaseBiz;
import ui.activity.profit.biz.RankingBiz;
import ui.activity.profit.contract.RankingContract;
import ui.model.RankingBean;

/**
 * Created by chenjian on 19/2/26
 */

public class RankingPresenter implements RankingContract.Presenter {

    RankingContract.View view;
    RankingBiz rankingBiz;
    List<RankingBean.ListBean> list = new ArrayList<>();

    @Inject
    public RankingPresenter(RankingContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        rankingBiz = (RankingBiz) biz;
    }


    @Override
    public void getInfo(final boolean isRefresh, int type, String strData) {
        if (isRefresh) {
            list.clear();
        }
        view.loading(true);
        rankingBiz.GetInComeDetail(type + "", strData, new BaseBiz.Callback<RankingBean>() {
            @Override
            public void onSuccess(RankingBean info) {
                list.addAll(info.getList());
                view.upDateUI(list, type);
                view.hasLoadMore(false);
                if (isRefresh) {
                    view.refreshComplete();
                } else {
                    view.loadMoreComplete();
                }
                view.loading(false);
            }

            @Override
            public void onFailure(RankingBean info) {
                view.loading(false);
                if (isRefresh) {
                    view.refreshComplete();
                } else {
                    view.loadMoreComplete();
                }
            }
        });
    }


}
